package net.lzzy.practicesapi1.utils;

import antlr.Token;
import com.alibaba.fastjson.JSONObject;
import net.lzzy.practicesapi1.web.models.BaseInfo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

public class AspectUtil {
    public static final String TOKEN = "Token";

    /**
     * @param point 业务方法参考
     * @return 解决得到的token
     */
    public static String getToken(ProceedingJoinPoint point) {
        Object[] args = point.getArgs();
        String[] names = ((MethodSignature) point.getSignature()).getParameterNames();
        int i = 0;
        for (String name : names) {
            if (TOKEN.equals(name)) {
                return args[i].toString();
            }
            i++;
        }
        if (args[0] instanceof BaseInfo) {
            return ((BaseInfo) args[0]).getToken();
        } else {
            JSONObject obj = (JSONObject) args[0];
            return obj.getString(TOKEN);
        }
    }
}

